package com.audible.library.database;

import com.audible.library.domain.beans.UserAudioBookRating;
import com.audible.library.domain.beans.UserAudioBookRatingPK;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * The class defines CRUD methods for UserAudioBookRating in the database.
 *
 * @author Jigar Shah
 * @version 0.1
 */
@Stateless
public class UserAudioBookRatingFacade extends AbstractFacade<UserAudioBookRating> {

    @PersistenceContext(unitName = "AudibleLibraryWebPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public UserAudioBookRatingFacade() {
        super(UserAudioBookRating.class);
    }

    /**
     * This method should return all the ratings by a user for a particular book.
          * 
     * @param userID a unique identifier of a user.
     * @param bookID a unique identifier of a book.
     * @return UserAudioBookRating an object representing a rating of an audio book
     */
    public UserAudioBookRating findRatingsByUserBook(int userID, int bookID) {
        UserAudioBookRatingPK pk = new UserAudioBookRatingPK();
        pk.setUserAudioBookUserProfileId(userID);
        pk.setUserAudioBookAudioBookId(bookID);
        return (UserAudioBookRating)find(pk);
    }
}
